package com.lezhu.plcsdklibrary.manager;

import com.lezhu.plcsdklibrary.callback.OpenDoorListener;

import java.util.HashMap;

/**
 * 描述:所有柜门状态回调管理
 * 作者: 钮家齐
 * 时间: 2020/6/1 9:11
 */
public class OpenDoorCallBackManager {

    private static HashMap<Integer, OpenDoorListener> map;
    private static OpenDoorCallBackManager doorStatusCallBackManager;

    public static OpenDoorCallBackManager getInstance(){
        if(doorStatusCallBackManager==null){
            synchronized (OpenDoorCallBackManager.class){
                if(doorStatusCallBackManager==null){
                    doorStatusCallBackManager = new OpenDoorCallBackManager();
                    map = new HashMap<>();
                }
            }
        }
        return doorStatusCallBackManager;
    }


    public void addDoorListener(int pos,OpenDoorListener statusInterface){
        map.put(pos,statusInterface);
    }

    public void onSuccess(int pos){
        if(map.containsKey(pos)){
            OpenDoorListener doorStatusInterface = map.get(pos);
            doorStatusInterface.onOpenSuccess(pos);
            map.remove(pos);
        }
    }

}
